import { prisma } from "../prisma/client";
import { PaginationUtil } from "../utils/pagination.util";
// 获取所有部门
export const getAllDepartments = async (
  page: number = 1,
  pageSize: number = 10,
  options: object = {}
) => {
  return PaginationUtil.paginate(prisma.department, options, page, pageSize);
};

// 根据ID获取部门
export const getDepartmentById = async (id: number) => {
  return await prisma.department.findUnique({
    where: { id },
    include: {
      users: true,
    },
  });
};

// 创建部门
export const createDepartment = async (data: {
  name: string;
  note: string;
}) => {
  return await prisma.department.create({
    data,
  });
};

// 更新部门
export const updateDepartment = async (
  id: number,
  data: {
    name?: string;
    note?: string;
  }
) => {
  return await prisma.department.update({
    where: { id },
    data,
  });
};

// 删除角色
export const deleteDepartment = async (id: number) => {
  return await prisma.department.delete({
    where: {
      id,
    },
  });
};
